<template>
  <div class="home">
    <div class="title">积分数据看板</div>
    <div class="system_points">
      <div class="system_points_title">系统积分</div>
      <SystemPoints ref="SystemPointsRef"></SystemPoints>
    </div>
    <div
      style="
        display: flex;
        justify-content: space-between;
        flex: 1;
        width: 70%;
        margin-bottom: 20px;
      "
    >
      <div class="mall_points">
        <div class="mall_points_title">店铺积分</div>
        <div class="mall_points_content">
          <div class="mall_points_content_item">
            <span class="num">{{ data.consumptionRuleSettings }}</span>
            <div class="zt1" :style="{ height: zt1Height }"></div>
            <span class="name">消费积分总额</span>
          </div>
          <div class="mall_points_content_item">
            <span class="num">{{ data.shopRefundRuleSettings }}</span>
            <div class="zt2" :style="{ height: zt2Height }"></div>
            <span class="name">退款积分总额</span>
          </div>
        </div>
      </div>
      <div class="user_points">
        <div class="user_points_title">用户积分</div>
        <div class="all_num">
          <div class="all_num_num">{{ data.userRuleSettingsBalance }}</div>
          <div class="all_num_text">积分总余额</div>
        </div>
        <div class="user_points_content">
          <div class="user_points_content_item">
            <span class="num">{{ data.userConsumptionRuleSettings }}</span>
            <div class="zt3" :style="{ height: zt3Height }"></div>
            <span class="name">消费积分总额</span>
          </div>
          <div class="user_points_content_item">
            <span class="num">{{ data.userIncomeRuleSettings }}</span>
            <div class="zt4" :style="{ height: zt4Height }"></div>
            <span class="name">收入积分总余额</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import SystemPoints from './components/SystemPoints.vue'
import { apiGetData } from '@/api/home/index.js'
export default {
  name: 'home',
  components: {
    SystemPoints,
  },
  data() {
    return {
      data: {},
      zt1Height: '100%',
      zt2Height: '100%',
      zt3Height: '100%',
      zt4Height: '100%',
    }
  },
  mounted() {
    apiGetData().then((res) => {
      // 发现数据有问题，所以先写死数据进行展示
      // res.consumptionRuleSettings = 1000
      // res.userConsumptionRuleSettings = 1000
      this.data = res
      this.$refs.SystemPointsRef.init(res)
      const {
        consumptionRuleSettings,
        shopRefundRuleSettings,
        userConsumptionRuleSettings,
        userIncomeRuleSettings,
      } = res
      // 计算高度百分比，注意最小高度设置为10%
      if (-consumptionRuleSettings > shopRefundRuleSettings) {
        let height = (shopRefundRuleSettings / -consumptionRuleSettings) * 100
        if (height < 10) {
          height = 10
        }
        this.zt2Height = height + '%'
      }
      if (shopRefundRuleSettings > -consumptionRuleSettings) {
        let height = (-consumptionRuleSettings / shopRefundRuleSettings) * 100
        if (height < 10) {
          height = 10
        }
        this.zt1Height = height + '%'
      }
      if (-userConsumptionRuleSettings > userIncomeRuleSettings) {
        let height =
          (userIncomeRuleSettings / -userConsumptionRuleSettings) * 100
        if (height < 10) {
          height = 10
        }
        this.zt4Height = height + '%'
      }
      if (userIncomeRuleSettings > -userConsumptionRuleSettings) {
        let height =
          (-userConsumptionRuleSettings / userIncomeRuleSettings) * 100
        if (height < 10) {
          height = 10
        }
        this.zt3Height = height + '%'
      }
    })
  },
}
</script>

<style lang="scss" scoped>
.home {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  width: 100%;
  height: calc(100vh - 86px);
  background-color: #051430ff;
  .title {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 480px;
    height: 120px;
    font-weight: 600;
    font-size: 28px;
    color: #ffffff;
    background-image: url('./bgk.png');
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center;
  }
  .system_points {
    position: relative;
    margin-bottom: 20px;
    flex: 1;
    width: 70%;
    height: 200px;
    background: rgba(207, 222, 250, 0.06);
    border-radius: 16px;
    &_title {
      display: flex;
      align-items: center;
      justify-content: center;
      position: absolute;
      top: 20px;
      font-weight: 600;
      font-size: 22px;
      color: #ffffff;
      width: 151px;
      height: 46px;
      background: linear-gradient(
        270deg,
        rgba(78, 171, 255, 0) 0%,
        rgba($color: #2672ff, $alpha: 0.2) 100%
      );
      &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        width: 8px;
        height: 46px;
        background: #2672ff;
        border-radius: 4px;
      }
    }
  }
  .mall_points,
  .user_points {
    position: relative;
    flex: 1;
    height: 100%;
    background: rgba(207, 222, 250, 0.06);
    border-radius: 16px;
    &_title {
      display: flex;
      align-items: center;
      justify-content: center;
      position: absolute;
      top: 20px;
      font-weight: 600;
      font-size: 22px;
      color: #ffffff;
      width: 151px;
      height: 46px;
      background: linear-gradient(
        270deg,
        rgba(78, 171, 255, 0) 0%,
        rgba($color: #2672ff, $alpha: 0.2) 100%
      );
      &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        width: 8px;
        height: 46px;
        background: #2672ff;
        border-radius: 4px;
      }
    }
  }
  .mall_points_content {
    padding: 20px;
    box-sizing: border-box;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    &_item {
      height: 80%;
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      align-items: center;
      .num {
        font-weight: 600;
        font-size: 22px;
        color: #ffffff;
      }
      .zt1 {
        margin: 10px 0;
        width: 16px;
        background: linear-gradient(
          180deg,
          #2672ff 0%,
          rgba(38, 114, 255, 0) 100%
        );
        border-radius: 2px 2px 0px 0px;
      }
      .zt2 {
        margin: 10px 0;
        width: 16px;
        background: linear-gradient(
          180deg,
          #f0d66b 0%,
          rgba(240, 214, 107, 0) 100%
        );
        border-radius: 2px 2px 0px 0px;
      }
      .name {
        font-weight: 400;
        font-size: 14px;
        color: #ffffff;
      }
    }
    &_item:last-child {
      margin-left: 40px;
    }
  }
  .user_points {
    display: flex;
    flex-direction: column;
    margin-left: 20px;
    .all_num {
      padding-top: 15%;
      text-align: center;
      &_num {
        font-size: 28px;
        color: #ffffff;
      }
      &_text {
        font-size: 14px;
        color: #ffffff;
      }
    }
    &_content {
      padding: 20px;
      box-sizing: border-box;
      display: flex;
      flex: 1;
      justify-content: center;
      align-items: flex-end;
      &_item {
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: center;
        .num {
          font-weight: 600;
          font-size: 22px;
          color: #ffffff;
        }
        .zt3 {
          margin: 10px 0;
          width: 16px;
          height: 50px;
          background: linear-gradient(
            180deg,
            #2672ff 0%,
            rgba(38, 114, 255, 0) 100%
          );
          border-radius: 2px 2px 0px 0px;
        }
        .zt4 {
          margin: 10px 0;
          width: 16px;
          height: 20px;
          background: linear-gradient(
            180deg,
            #f0d66b 0%,
            rgba(240, 214, 107, 0) 100%
          );
          border-radius: 2px 2px 0px 0px;
        }
        .name {
          font-weight: 400;
          font-size: 14px;
          color: #ffffff;
        }
      }
      &_item:last-child {
        margin-left: 40px;
      }
    }
  }
}
</style>
